<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>详情页</h1>
    <script>
        console.log(localStorage._id);
        console.log(sessionStorage._id);

        // console.log(location.search);
        // console.log(location.search.split("=")[1]);


        showProduct();

        // 2. 接收请求结果
        function showProduct() {
            // 从页面路径中获取产品_id
            const _id = location.search.split("=")[1];

            if (_id) {
                // 进入if，表示获取到了产品_id
                getData(_id)
                    .then((res) => {
                        console.log('请求成功的结果', res)
                        // productRender(res.data);
                    })
                    .catch((err) => {
                        console.log('请求出错', err);
                    })
            }

        }

        // 1. 发送请求
        async function getData(_id) {
            const response = await fetch(`http://nocat.life:3021/product/detail/${_id}`, {
                method: 'GET',
            })
            return response.json();
        }
    </script>
</body>

</html>